﻿using dotUML.Core.Common;
using dotUML.Core.Common.SequenceDiagram;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace CommonTest
{
    
    
    /// <summary>
    ///This is a test class for SequenceDiagramTest and is intended
    ///to contain all SequenceDiagramTest Unit Tests
    ///</summary>
    [TestClass()]
    public class SequenceDiagramTest
    {


        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        /// <summary>
        ///A test for DeleteLifeline
        ///</summary>
        [TestMethod()]
        public void DeleteLifelineTest()
        {
            string lifelineName = "lifeline1";

            IModel model = ModelFactory.GetModel();
            ISequenceDiagram sd = model.AddSequenceDiagram("SequenceDiagram1");

            sd.AddLifeline(lifelineName, ELifelineType.Normal);
            ILifeline l = sd.GetLifeline(lifelineName);
            Assert.IsNotNull(l);

            sd.DeleteLifeline(lifelineName);
            l = sd.GetLifeline(lifelineName);
            Assert.IsNull(l);
        }

        /// <summary>
        ///A test for GetLifeline
        ///</summary>
        [TestMethod()]
        public void GetLifelineTest()
        {
            string lifelineName = "lifeline1";

            IModel model = ModelFactory.GetModel();
            ISequenceDiagram sd = model.AddSequenceDiagram("SequeceDiagram1");

            ILifeline lAdded = sd.AddLifeline(lifelineName, ELifelineType.Normal);
            ILifeline l = sd.GetLifeline(lifelineName);
            Assert.AreSame(lAdded, l);

            l = sd.GetLifeline("lifeline2");
            Assert.IsNull(l);
        }

        /// <summary>
        ///A test for AddLifeline
        ///</summary>
        [TestMethod()]
        public void AddLifelineTest()
        {
            IModel model = ModelFactory.GetModel();
            ISequenceDiagram sd = model.AddSequenceDiagram("SequenceDiagram1");

            ILifeline l1 = sd.AddLifeline("lifeline1", ELifelineType.Normal);
            Assert.IsNotNull(l1);

            ILifeline l2 = sd.AddLifeline("lifeline2", ELifelineType.Normal);
            Assert.IsNotNull(l2);

            try
            {
                ILifeline l3 = sd.AddLifeline("lifeline1", ELifelineType.Normal);
                Assert.Fail("It was possible to add a lifeline with the same name twice.");
            }
            catch (CommonException)
            {
            }
        }

        /// <summary>
        ///A test for SequenceDiagram Constructor
        ///</summary>
        [TestMethod()]
        public void SequenceDiagramConstructorTest()
        {
            SequenceDiagram target = new SequenceDiagram();
            Assert.IsNotNull(target);
            Assert.IsNotNull(target.Lifelines);
            Assert.IsNotNull(target.LifelinesNames);
        }
    }
}
